package com.example.cymjoe.huaweishopping;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.cymjoe.huaweishopping.adapter.MyAdapter;
import com.example.cymjoe.huaweishopping.fragment.fragment2.CSFragment;
import com.example.cymjoe.huaweishopping.fragment.fragment2.JBFragment;
import com.example.cymjoe.huaweishopping.fragment.fragment2.PJFragment;
import com.example.cymjoe.huaweishopping.fragment.fragment2.TWFragment;

import java.util.ArrayList;
import java.util.List;

public class SPXQActivity extends AppCompatActivity {

    private ImageView back2;
    private ImageView ty;
    private ViewPager vp;
    private List<Fragment> data = new ArrayList<>();
    private RadioButton jbxx;
    private RadioButton twxq;
    private RadioButton cs;
    private RadioButton pj;
    private RadioGroup rrt;

    CSFragment csFragment;
    JBFragment jbFragment;
    PJFragment pjFragment;
    TWFragment twFragment;
private MyApp myApp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pxq);


        // String path="http://mw.vmall.com/product/getPrdInfoNew.json?prdId="+prdId;
        csFragment = new CSFragment();
        jbFragment = new JBFragment();

        pjFragment = new PJFragment();
        twFragment = new TWFragment();
        initView();
        listener();
        vp.setAdapter(new MyAdapter(getSupportFragmentManager(), data, this));
        myApp = (MyApp) getApplication();
        Intent intent=getIntent();
        String prdId = intent.getStringExtra("prdId");
        myApp.setSs(prdId);

    }

    private void listener() {
        ty.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        back2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        jbxx.setChecked(true);
                        jbxx.setTextColor(Color.RED);
                        twxq.setTextColor(Color.BLACK);
                        cs.setTextColor(Color.BLACK);
                        pj.setTextColor(Color.BLACK);
                        break;
                    case 1:
                        twxq.setChecked(true);
                        twxq.setTextColor(Color.RED);
                        jbxx.setTextColor(Color.BLACK);
                        cs.setTextColor(Color.BLACK);
                        pj.setTextColor(Color.BLACK);
                        break;
                    case 2:
                        cs.setChecked(true);
                        cs.setTextColor(Color.RED);
                        twxq.setTextColor(Color.BLACK);
                        jbxx.setTextColor(Color.BLACK);
                        pj.setTextColor(Color.BLACK);
                        break;
                    case 3:
                        pj.setChecked(true);
                        pj.setTextColor(Color.RED);
                        twxq.setTextColor(Color.BLACK);
                        cs.setTextColor(Color.BLACK);
                        jbxx.setTextColor(Color.BLACK);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        rrt.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {

                    case R.id.jbxx:

                        vp.setCurrentItem(0);
                        jbxx.setTextColor(Color.RED);
                        twxq.setTextColor(Color.BLACK);
                        cs.setTextColor(Color.BLACK);
                        pj.setTextColor(Color.BLACK);

                        break;
                    case R.id.twxq:
                        vp.setCurrentItem(1);
                        twxq.setTextColor(Color.RED);
                        jbxx.setTextColor(Color.BLACK);
                        cs.setTextColor(Color.BLACK);
                        pj.setTextColor(Color.BLACK);
                        break;
                    case R.id.cs:
                        vp.setCurrentItem(2);
                        cs.setTextColor(Color.RED);
                        twxq.setTextColor(Color.BLACK);
                        jbxx.setTextColor(Color.BLACK);
                        pj.setTextColor(Color.BLACK);
                        break;
                    case R.id.pj:
                        vp.setCurrentItem(3);
                        pj.setTextColor(Color.RED);
                        twxq.setTextColor(Color.BLACK);
                        cs.setTextColor(Color.BLACK);
                        jbxx.setTextColor(Color.BLACK);
                        break;

                }
            }

        });
    }

    private void initView() {
        rrt = ((RadioGroup) findViewById(R.id.rrt));
        vp = ((ViewPager) findViewById(R.id.vp));
        back2 = ((ImageView) findViewById(R.id.back2));
        ty = ((ImageView) findViewById(R.id.ty));
        jbxx = ((RadioButton) findViewById(R.id.jbxx));
        twxq = ((RadioButton) findViewById(R.id.twxq));
        cs = ((RadioButton) findViewById(R.id.cs));
        pj = ((RadioButton) findViewById(R.id.pj));

        data.add(jbFragment);
        data.add(twFragment);
        data.add(csFragment);
        data.add(pjFragment);

    }


}
